/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tecbooks;

import javax.swing.JOptionPane;

/**
 *
 * @author ifal
 */
public class CadastroCliente extends javax.swing.JFrame {

    /**
     * Creates new form CadastroCliente
     */
    public CadastroCliente() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modtify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        PaneCadastroCliente = new javax.swing.JPanel();
        lblNomeCliente = new javax.swing.JLabel();
        lblEnderecoCliente = new javax.swing.JLabel();
        lblTelefoneCliente = new javax.swing.JLabel();
        lblEmailCliente = new javax.swing.JLabel();
        txtNomeCliente = new javax.swing.JTextField();
        lblRua = new javax.swing.JLabel();
        lblNumero = new javax.swing.JLabel();
        lblBairro = new javax.swing.JLabel();
        txtRuaCliente = new javax.swing.JTextField();
        txtBairroCliente = new javax.swing.JTextField();
        txtEmailCliente = new javax.swing.JTextField();
        btnOkCliente = new javax.swing.JButton();
        btnSairCliente = new javax.swing.JButton();
        btnLimparCliente = new javax.swing.JButton();
        lblAvisoCliente = new javax.swing.JLabel();
        txtNumeroCasaCliente = new javax.swing.JTextField();
        txtTelefoneCliente = new javax.swing.JTextField();
        lblEstado = new javax.swing.JLabel();
        lblCidade = new javax.swing.JLabel();
        txtEstado = new javax.swing.JTextField();
        txtCidade = new javax.swing.JTextField();
        lblCep = new javax.swing.JLabel();
        txtCep = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        txtId = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Cadastro de Cliente");
        setResizable(false);

        PaneCadastroCliente.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 4, true), "Dados do Cliente", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tunga", 0, 24))); // NOI18N
        PaneCadastroCliente.setPreferredSize(new java.awt.Dimension(600, 406));

        lblNomeCliente.setText("Nome*:");

        lblEnderecoCliente.setText("Endereço:");

        lblTelefoneCliente.setText("Telefone*:");

        lblEmailCliente.setText("Email*:");

        txtNomeCliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                apenasStrings(evt);
            }
        });

        lblRua.setText("Rua/Avenida:");

        lblNumero.setText("Nº:");

        lblBairro.setText("Bairro:");

        txtRuaCliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                apenasStrings(evt);
            }
        });

        txtBairroCliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                apenasStrings(evt);
            }
        });

        btnOkCliente.setText("OK");
        btnOkCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOkClienteActionPerformed(evt);
            }
        });

        btnSairCliente.setText("Sair");
        btnSairCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSairClienteActionPerformed(evt);
            }
        });

        btnLimparCliente.setText("Limpar");
        btnLimparCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimparClienteActionPerformed(evt);
            }
        });

        lblAvisoCliente.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
        lblAvisoCliente.setForeground(new java.awt.Color(255, 0, 0));

        txtNumeroCasaCliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                apenasNumeros(evt);
            }
        });

        txtTelefoneCliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                apenasNumeros(evt);
            }
        });

        lblEstado.setText("Estado:");

        lblCidade.setText("Cidade:");

        txtEstado.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                apenasStrings(evt);
            }
        });

        txtCidade.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                apenasStrings(evt);
            }
        });

        lblCep.setText("CEP:");

        txtCep.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                apenasNumeros(evt);
            }
        });

        jLabel1.setText("ID:");

        txtId.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                apenasNumeros(evt);
            }
        });

        org.jdesktop.layout.GroupLayout PaneCadastroClienteLayout = new org.jdesktop.layout.GroupLayout(PaneCadastroCliente);
        PaneCadastroCliente.setLayout(PaneCadastroClienteLayout);
        PaneCadastroClienteLayout.setHorizontalGroup(
            PaneCadastroClienteLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(PaneCadastroClienteLayout.createSequentialGroup()
                .addContainerGap()
                .add(PaneCadastroClienteLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(PaneCadastroClienteLayout.createSequentialGroup()
                        .add(141, 141, 141)
                        .add(btnOkCliente)
                        .add(18, 18, 18)
                        .add(btnLimparCliente)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btnSairCliente))
                    .add(lblEnderecoCliente)
                    .add(PaneCadastroClienteLayout.createSequentialGroup()
                        .add(lblTelefoneCliente)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(txtTelefoneCliente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(PaneCadastroClienteLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                        .add(PaneCadastroClienteLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, PaneCadastroClienteLayout.createSequentialGroup()
                                .add(lblEstado)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(txtEstado, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 155, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(lblCidade)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(txtCidade))
                            .add(org.jdesktop.layout.GroupLayout.LEADING, PaneCadastroClienteLayout.createSequentialGroup()
                                .add(lblNomeCliente)
                                .add(2, 2, 2)
                                .add(txtNomeCliente))
                            .add(org.jdesktop.layout.GroupLayout.LEADING, PaneCadastroClienteLayout.createSequentialGroup()
                                .add(PaneCadastroClienteLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, PaneCadastroClienteLayout.createSequentialGroup()
                                        .add(lblBairro)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(txtBairroCliente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 248, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(18, 18, 18)
                                        .add(lblCep)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(txtCep))
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, PaneCadastroClienteLayout.createSequentialGroup()
                                        .add(lblRua)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(txtRuaCliente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 351, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(lblNumero)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(txtNumeroCasaCliente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 27, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .add(org.jdesktop.layout.GroupLayout.LEADING, PaneCadastroClienteLayout.createSequentialGroup()
                            .add(lblEmailCliente)
                            .add(1, 1, 1)
                            .add(txtEmailCliente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 386, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(lblAvisoCliente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 381, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(PaneCadastroClienteLayout.createSequentialGroup()
                        .add(jLabel1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(txtId, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 76, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(49, Short.MAX_VALUE))
        );
        PaneCadastroClienteLayout.setVerticalGroup(
            PaneCadastroClienteLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(PaneCadastroClienteLayout.createSequentialGroup()
                .add(PaneCadastroClienteLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(txtId, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(4, 4, 4)
                .add(PaneCadastroClienteLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblNomeCliente)
                    .add(txtNomeCliente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(lblEnderecoCliente)
                .add(5, 5, 5)
                .add(PaneCadastroClienteLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblEstado)
                    .add(lblCidade)
                    .add(txtEstado, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(txtCidade, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(PaneCadastroClienteLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(txtBairroCliente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(lblCep)
                    .add(txtCep, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(lblBairro))
                .add(8, 8, 8)
                .add(PaneCadastroClienteLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblRua)
                    .add(txtRuaCliente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(lblNumero)
                    .add(txtNumeroCasaCliente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(PaneCadastroClienteLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblTelefoneCliente)
                    .add(txtTelefoneCliente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(PaneCadastroClienteLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(lblEmailCliente)
                    .add(txtEmailCliente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(21, 21, 21)
                .add(PaneCadastroClienteLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(btnOkCliente)
                    .add(btnSairCliente)
                    .add(btnLimparCliente))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(lblAvisoCliente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 17, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(41, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(34, 34, 34)
                .add(PaneCadastroCliente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 553, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(82, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(PaneCadastroCliente, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnOkClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkClienteActionPerformed
        // TODO add your handling code here:
        if(txtNomeCliente.getText().isEmpty() || txtTelefoneCliente.getText().isEmpty() || txtEmailCliente.getText().isEmpty()){
            lblAvisoCliente.setText("Preencha os campos obrigatórios!");
        }
        else{
            JOptionPane.showMessageDialog(null, "Cadastro Realizado com sucesso!");
            dispose();
            TelaPrincipal tela = new TelaPrincipal();
            tela.setVisible(true);
        }
    }//GEN-LAST:event_btnOkClienteActionPerformed

    private void btnLimparClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimparClienteActionPerformed
        // TODO add your handling code here:
        txtNomeCliente.setText("");
        txtRuaCliente.setText("");
        txtBairroCliente.setText("");
        txtTelefoneCliente.setText("");
        txtEmailCliente.setText(""); 
        txtEstado.setText("");
        txtCidade.setText("");
        txtCep.setText("");
        txtNumeroCasaCliente.setText("");
    }//GEN-LAST:event_btnLimparClienteActionPerformed

    private void btnSairClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairClienteActionPerformed
        // TODO add your handling code here:
        dispose();
        TelaPrincipal tela = new TelaPrincipal();
        tela.setVisible(true);
    }//GEN-LAST:event_btnSairClienteActionPerformed

    private void apenasNumeros(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_apenasNumeros
        // TODO add your handling code here:
        String numeros = "0123456789";
        if(!numeros.contains(evt.getKeyChar()+"") && (int)evt.getKeyChar() != 8){
            evt.consume();
            lblAvisoCliente.setText("Por favor, informe apenas números!");
        }
        else{
           lblAvisoCliente.setText("");
        }
    }//GEN-LAST:event_apenasNumeros

    private void apenasStrings(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_apenasStrings
        // TODO add your handling code here:
        String numeros = "0123456789";
        if(numeros.contains(evt.getKeyChar()+"")){
            evt.consume();
            lblAvisoCliente.setText("Por favor, informe apenas letras!");
        }
        else{
           lblAvisoCliente.setText("");
        }
    }//GEN-LAST:event_apenasStrings
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CadastroCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CadastroCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CadastroCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CadastroCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CadastroCliente().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel PaneCadastroCliente;
    private javax.swing.JButton btnLimparCliente;
    private javax.swing.JButton btnOkCliente;
    private javax.swing.JButton btnSairCliente;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel lblAvisoCliente;
    private javax.swing.JLabel lblBairro;
    private javax.swing.JLabel lblCep;
    private javax.swing.JLabel lblCidade;
    private javax.swing.JLabel lblEmailCliente;
    private javax.swing.JLabel lblEnderecoCliente;
    private javax.swing.JLabel lblEstado;
    private javax.swing.JLabel lblNomeCliente;
    private javax.swing.JLabel lblNumero;
    private javax.swing.JLabel lblRua;
    private javax.swing.JLabel lblTelefoneCliente;
    private javax.swing.JTextField txtBairroCliente;
    private javax.swing.JTextField txtCep;
    private javax.swing.JTextField txtCidade;
    private javax.swing.JTextField txtEmailCliente;
    private javax.swing.JTextField txtEstado;
    private javax.swing.JTextField txtId;
    private javax.swing.JTextField txtNomeCliente;
    private javax.swing.JTextField txtNumeroCasaCliente;
    private javax.swing.JTextField txtRuaCliente;
    private javax.swing.JTextField txtTelefoneCliente;
    // End of variables declaration//GEN-END:variables
}
